package com.eastfair.venueservice.controller;

import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.core.utils.ConvertUtil;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.entity.ServicePriceListDetail;
import com.eastfair.venueservice.entity.ServicePriceListItem;
import com.eastfair.venueservice.service.ServicePriceListDetailService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;


/**
 * <p>
 * 前端控制器
 * 服务价目信息明细表
 * </p>
 *
 * @author linan
 * @date 2022-07-21
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/servicePriceListDetail")
@Api(value = "ServicePriceListDetail", tags = "服务价目信息明细表")
@PreAuth(replace = "venueservice:servicePriceListDetail:")
public class ServicePriceListDetailController extends SuperController<ServicePriceListDetailService, Long, ServicePriceListDetail, ServicePriceListDetailPageQuery, ServicePriceListDetailSaveDTO, ServicePriceListDetailUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<ServicePriceListDetail> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ServicePriceListDetail> servicePriceListDetailList = list.stream().map((map) -> {
            ServicePriceListDetail servicePriceListDetail = ServicePriceListDetail.builder().build();
            //TODO 请在这里完成转换
            return servicePriceListDetail;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(servicePriceListDetailList));
    }



    /**
     * 编辑规格价目明细
     *
     * @param servicePriceListDetails 编辑规格价目明细
     * @return R
     */
    @ApiOperation(value = "编辑规格价目明细", notes = "编辑规格价目明细")
    @PostMapping("/updatePriceListDetail")
    public R<Boolean> updatePriceListDetail(@RequestBody @Validated(ServicePriceListDetailDTO.Update.class) @NotEmpty(message = "参数不能为空") List<ServicePriceListDetailDTO> servicePriceListDetails) {
        log.info("updatePriceListDetail - 编辑规格价目明细 servicePriceListDetails={}", servicePriceListDetails);
        return R.success(baseService.updatePriceListDetail(servicePriceListDetails));
    }

}
